var util = require("../../../utils/util.js"),
{api} = require("../../../utils/api.js"),
app = getApp();
Page({

    data: {
        czIntegral: [],
        xfIntegral: [],
        statusFlag: 4,
        showEmpty: !1,
        tearoomIndex:0,
        amount:0,
        show:false,
        record:{},
        userInfo:{},
        configInfo:{},
        page:1,
        pageSize:10
    },
    onClickHide(){
        this.setData({show:false})
    },
    showModel(){
        this.setData({show:true})
    },
    onLoad(options) {
        console.log('options',options);
        if(options.type == 1){
            wx.setNavigationBarTitle({
              title: '签到详情',
            })
            this.setData({type:1})
            this.integralList(1)
        }else{
            this.integralList()
        }
        this.getUsers()
        
    },
    async getUsers(){
        const data = await app.getUsers();
        if(data){
            console.log('data',data);
            if(data.userInfo && this.data.type == 1){
                data.userInfo.score=data.integral.total_sign_integral;
            }
            this.setData(data)
        }
    },
    async integralList(type=null){
        var parmes = {
            page: this.data.page,
            pageSize:this.data.pageSize,
            operate_type:this.data.tearoomIndex
        };
        if(type == 1){
            parmes.type=1;
        }
        let {data} = await api.integralList(parmes);
        let listArr = data && data.list && Array.isArray(data.list.data) ? data.list.data : [];
        let total= data && data.list && data.list.total?data.list.total:0;
        this.setData({
            showEmpty: total == 0 ? true : false,
            czIntegral: this.data.page == 1 ? listArr : [...this.data.czIntegral, ...listArr],
            pageScroll: listArr.length < 10 ? false : true
        })
    },
    changeTab(e){
        this.setData({tearoomIndex:e.currentTarget.dataset.flag,page:1});
        this.integralList()
    },
    onShareAppMessage(e) {
        return util.shareEvent(e)
      }
})